package com.aia.prm.web;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.json.JSONObject;

import com.aia.prm.BeanFactory;
import com.aia.prm.domain.VOLms;
import com.aia.prm.service.DefaultService;
import com.cfh.util.Tools;

public class MyHelper {
	private static final Logger logger = Logger.getLogger(MyHelper.class);
	private static final String NULL_OBJECT = "null";

	private MyHelper() {
	}

	public static void main(String[] args) {
		System.out.println(MyHelper.toLmsJson("88F643D8-AAA3-DD25-335A-EBA2EC0BE535"));
	}

	public static String toLmsJson(String refid) {
		if (!Tools.hasText(refid)) {
			return NULL_OBJECT;
		}
		try {
			DefaultService defaultService = (DefaultService) BeanFactory.get().getBean("defaultService");
			VOLms vo = defaultService.fetchOneLms(refid);
			if (vo == null) {
				return NULL_OBJECT;
			}
			Map<String, Object> prepareMap = new HashMap<String, Object>();
			prepareMap.put("LMS_GUID", vo.getLMS_GUID());
			prepareMap.put("LMS_BB_SEX", vo.getLMS_BB_SEX());
			prepareMap.put("LMS_BB_AGE", vo.getLMS_BB_AGE());
			prepareMap.put("LMS_BB_PROVINCE", vo.getLMS_BB_PROVINCE());
			prepareMap.put("LMS_BB_CITY", vo.getLMS_BB_CITY());
			prepareMap.put("LMS_BB_DISTRICT", vo.getLMS_BB_DISTRICT());
			prepareMap.put("LMS_LX_SEX", vo.getLMS_LX_SEX());
			prepareMap.put("LMS_LX_AGE", vo.getLMS_LX_AGE());
			prepareMap.put("LMS_LX_PROVINCE", vo.getLMS_LX_PROVINCE());
			prepareMap.put("LMS_LX_CITY", vo.getLMS_LX_CITY());
			prepareMap.put("LMS_LX_DISTRICT", vo.getLMS_LX_DISTRICT());
			prepareMap.put("LMS_LX_NAME", vo.getLMS_LX_NAME());
			prepareMap.put("LMS_RELATION", vo.getLMS_RELATION());
			prepareMap.put("LMS_MOBILE", vo.getLMS_MOBILE());
			prepareMap.put("PL_ID", vo.getPL_ID());
			prepareMap.put("GP_PK", vo.getGP_PK());
			prepareMap.put("GP_NAME", vo.getGP_NAME());
			prepareMap.put("GP_TYPE1", vo.getGP_TYPE1());
			prepareMap.put("GP_TYPE2", vo.getGP_TYPE2());
			prepareMap.put("GP_TYPE3", vo.getGP_TYPE3());
			prepareMap.put("LMS_INSU_AMOUT", vo.getLMS_INSU_AMOUT());
			JSONObject jsonObject = new JSONObject(prepareMap);
			return jsonObject.toString(2);
		} catch (Throwable e) {
			logger.warn(e);
			return NULL_OBJECT;
		}
	}

}
